import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * rateTypeService.js - 汇率类型 service
 * @date: 2018-10-24
 */
import request from 'utils/request';
import { parseParameters, isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
var tenantId = getCurrentOrganizationId();

function rateTypeApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/exchange-rate-types") : 'exchange-rate-types';
}
/**
 * 查询平台级汇率类型
 * @param {Object} params - 查询参数
 */


export function queryRateType(_x) {
  return _queryRateType.apply(this, arguments);
}
/**
 * 新增汇率类型
 * @param {Object} params 新增汇率类型
 */

function _queryRateType() {
  _queryRateType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateTypeApi()), {
              method: 'GET',
              query: parseParameters(params)
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryRateType.apply(this, arguments);
}

export function insertRateType(_x2) {
  return _insertRateType.apply(this, arguments);
}
/**
 * 批量删除汇率类型
 * @param {Array} params 批量删除汇率类型
 */

function _insertRateType() {
  _insertRateType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateTypeApi()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _insertRateType.apply(this, arguments);
}

export function deleteRateType(_x3) {
  return _deleteRateType.apply(this, arguments);
}
/**
 * 修改平台级汇率类型
 * @param {Object} params 修改参数
 */

function _deleteRateType() {
  _deleteRateType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateTypeApi()), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _deleteRateType.apply(this, arguments);
}

export function updateRateType(_x4) {
  return _updateRateType.apply(this, arguments);
}
/**
 * 查询汇率类型明细
 * @param {Number} rateTypeId 汇率类型 Id
 * @param {Object} params 汇率类型明细查询参数
 */

function _updateRateType() {
  _updateRateType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateTypeApi()), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateRateType.apply(this, arguments);
}

export function queryRateTypeDetail(_x5) {
  return _queryRateTypeDetail.apply(this, arguments);
}
/**
 * 根据 rateTypeId 查询汇率类型信息
 * @param {Number} rateTypeId 汇率类型 ID
 */

function _queryRateTypeDetail() {
  _queryRateTypeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateTypeApi(), "/tenants"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryRateTypeDetail.apply(this, arguments);
}

export function queryRateTypeInfo(_x6) {
  return _queryRateTypeInfo.apply(this, arguments);
}

function _queryRateTypeInfo() {
  _queryRateTypeInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(rateTypeId) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(rateTypeApi(), "/").concat(rateTypeId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryRateTypeInfo.apply(this, arguments);
}